package com.Thread;

/**
 * @ClassName Demo5
 * @Description 编写程序，使用多线程，实现电影院售票的过程。
 * 多个线程各自卖自己的50张票 -- 继承 Thread
 * @Author Kx
 * @Date 2025/3/11 13:44
 * @Version 1.0
 */
public class Demo5 {
    public static void main(String[] args) {
        MyThread3 thread1 = new MyThread3();
        MyThread3 thread2 = new MyThread3();
        MyThread3 thread3 = new MyThread3();

        // 设置线程名
        thread1.setName("线程一");
        thread2.setName("线程二");
        thread3.setName("线程三");

        // 启动线程
        thread1.start();
        thread2.start();
        thread3.start();
    }
}

class MyThread3 extends Thread {
    private int tickets = 50;
    @Override
    public void run() {
        while (tickets > 0){
            System.out.println(Thread.currentThread().getName() + "卖出了第" + tickets-- + "张票");
        }
    }

    public int getTickets() {
        return tickets;
    }

    public void setTickets(int tickets) {
        this.tickets = tickets;
    }
}
